package ninja.awesome.game.main;

import ninja.awesome.framework.Graphics;
import ninja.awesome.framework.Image;

public class Animation {

	private int speed;
	private int index = 0;
	private int count = 0;
	private int imageNumber = 0;
	private int tempNumber = 0;
	private double imageHeight = 0;
	private double imageWidth = 0;
	private int action =0;

	private Image img;

	public Animation(int speed, Image img, double imageHeight,
			double imageWidth, int imageNumber, int tempNumber) {
		this.speed = speed;
		this.img = img;
		this.imageHeight = imageHeight; // Height of the image by pixel
		this.imageWidth = imageWidth; // Width of the single animation image by
										// pixel
		this.imageNumber = imageNumber; // The number of animation for the image
										// strip
		this.tempNumber = tempNumber; // The actual image we will be showing
										// starting with tempNumber
	}

	public Animation(int speed, Image img, double imageHeight,
			double imageWidth, int imageNumber) {
		this.speed = speed;
		this.img = img;
		this.imageHeight = imageHeight; // Height of the image by pixel
		this.imageWidth = imageWidth; // Width of the single animation image by
										// pixel
		this.imageNumber = imageNumber; // The number of animation for the image
										// strip
		this.tempNumber = 0; // The actual image we will be showing starting
								// with 0
	}

	public void runAnimation() {
		index++;
		if (index > speed) {
			index = 0;
			tempNumber++; // the image number we're actually looking at
		}
		if (tempNumber >= imageNumber) {
			tempNumber = 0;
		}
	}

	public void runtAnimationWithoutLoop() { // this source code for selecting
												// the one of the pictures
												// rather than looping the
												// pictures.
		index++;
		if (index > speed) {
			index = 0;
			tempNumber++;
		}
		if (tempNumber >= imageNumber) {
			tempNumber = imageNumber-1;
		}
	}

	public void drawAnimation(Graphics g, double x, double y) {
		g.drawImage(img, (int) x, (int) y, (int) x + (int) imageWidth, (int) y
				+ (int) imageHeight , (int) imageWidth * tempNumber, (int)imageHeight*action,
				(int) imageWidth * tempNumber + (int) imageWidth,
				(int)imageHeight* action + (int) imageHeight);
	} // drawImage(image, x-coordinate where the image is placed, y-coordinate
		// where the image is placed,
		// left-bound of where the image ends, right-bound of where the image
		// ends,
		// left-bound of image, lower-bound of the image, right-bound of image,
		// upper-bound of image, null);

	public void setCount(int count) {
		this.count = count;
	}

	public int getCount() {
		return count;
	}

	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public void setImageHeight(int imageHeight) {
		this.imageHeight = imageHeight;

	}

	public void setImageWidth(int imageWidth) {
		this.imageWidth = imageWidth;
	}

	public void setImageNumber(int imageNumber) {
		this.imageNumber = imageNumber;
	}

	public void setAction(int action){// set Image Action!
		this.action = action;
	}

	public int getImageNumber() {
		return this.imageNumber;
	}

	public void setTempNumber(int tempNumber){
		this.tempNumber = tempNumber;
	}

	public int getTempNumber() {
		return this.tempNumber;
	}// I added this function
		// for proper animation display!



	public void setImage(Image img) { // this area shall be remove!
		this.img = img;
	}

	public Image getImage() {
		return this.img;
	}

}
